<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
   <%@page import="wt.httpgw.URLFactory"%>
   <%@page import="shmged.com.shlcm.utils.CmCreateDocHelper"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<div>
<%
String baseUrl = new URLFactory().getBaseHREF();
%>
<center>
	<div style="margin:10px 0;"></div>
	<div class="easyui-layout" style="width:720px;height:550px;" id="treeFolders" name="treeFolders">
	
		<div data-options="region:'center',title:'查询文档',iconCls:''"> 
			<div style="padding:5px;">
			<div style="padding-left:50px">
				<table>
					<tr>
						<td>名称：</td>
						<td><input type="text" id="searchName" name="searchName"><br/></td>
					</tr>
					<tr>
						<td>编号：</td>
						<td><input type="text" id="searchNumber" name="searchNumber"><br/></td>
					</tr>
					<tr>
						<td>更新日期：</td>
						<td><input class="easyui-datebox" id="beginTime"  name="beginTime" data-options="formatter:myformatter,parser:myparser"></input>-<input id="endTime" name="endTime" class="easyui-datebox" data-options="formatter:myformatter,parser:myparser"></input></td>
					</tr>
					<tr>
						<td colspan="2" align="center">
						<a href="javascript:void(0)" class="easyui-linkbutton" id="searId" onclick="initDocsTable()">提交</a>
	    				<a href="javascript:void(0)" class="easyui-linkbutton" onclick="clearSeach()">清除</a>
						</td>
					</tr>
				</table>
				
			</div>
			<br/>
			<div style="padding:5px;display:none" id="buts" >
			<a href="#" class="easyui-linkbutton" data-options="iconCls:'icon-remove'" onclick="javaScript:deleteSearchDoc()">删除</a>
			<a href="#" class="easyui-linkbutton" onclick="javaScript:searchAddUpdateTab('','')">修改</a>
			</div>
			<table id="docTable"></table>
			</div>
	      
		</div>
	</div>
</center>
<script>
	function clearSeach()
	{
		$('#searchName').val()="";
		$('#searchNumber').val()="";
	}
	function initDocsTable()
	{

		document.getElementById("buts").style.display="";
		var name=$('#searchName').val();
		var number=$('#searchNumber').val();
		var beginTime="";
		var endTime="";
		var begin=document.getElementsByName("beginTime");
		for(var i=0;i<begin.length;i++)
		{
			if(begin[i].value!="")
			{
				beginTime=begin[i].value;
			}
			
		}
		var end=document.getElementsByName("endTime");
		for(var i=0;i<end.length;i++)
		{
			if(end[i].value!="")
			{
				endTime=end[i].value;
			}
			
		}
		var url='<%=baseUrl%>shmged/jsp/com/shlcm/documents/jspSearchDocs.jsp';
		  $('#docTable').datagrid({   
		      url:url,
		      queryParams:{name:name,number:number,beginTime:beginTime,endTime:endTime},
		      nowrap:false,
		      loadMsg:'正在加载数据，请稍等。。。',
			  fitColumns: true,
		      columns:[[   
				  {field:'id',title:'id',width:100,checkbox:true},  
				  {field:'type',title:'类型',width:15}, 
		          {field:'name',title:'名称',width:100,
		        	  //添加超级链 
                   formatter:function(value,rowData,rowIndex){
						if(rowData.number!=""){
                  		 return "<a href='javaScript:void(0)' onclick=\"javaScript:addTab('','','"+rowData.id+"','"+rowData.name+"')\">"+rowData.name+"</a>";  
						}else{
							  return "<a href='javaScript:void(0)' onclick=\"javaScript:expandTo('"+rowData.name+"')\">"+rowData.name+"</a>";
							}
		          }
			          },
		          {field:'state',title:'状态',width:100}, 
		          {field:'version',title:'版本',width:100},
		          {field:'modifyUser',title:'更新者',width:100},
		          {field:'time',title:'更新时间',width:100}  
		      ]] 
		    }); 
		}
	
	


	//或得table选中的并删除
	function deleteSearchDoc(){
		var rows = $('#docTable').datagrid('getSelections');
		var oids="";
		for(var i=0; i<rows.length; i++){
			var row = rows[i];
			oids+=row.id+"__";
		}
		if(rows.length)
		{
			deleteSearchObj(oids);
		}
		
	}

	function deleteSearchObj(oids)
	{
		var url='<%=baseUrl%>shmged/jsp/com/shlcm/documents/deleteObj.jsp';
		$.messager.confirm('提示', '确定删除？', function(flag){
			  if(flag){
			    var idata = {oids:oids};
		        jQuery.post(url,idata,function (data){
		   	       if(data.indexOf("SUCC")!=-1){
		   	    	$.messager.alert('提示', "删除成功");
		   	    	document.getElementById("searId").click();
		   	       }else{
		   	    	$.messager.alert('提示', data);
		   	       }
		        });
			 }
		  });
	}

	//创建一个新的tab 文档信息
	function searchAddUpdateTab(tabObj,tabId){
		var rows = $('#docTable').datagrid('getSelections');
		if(rows.length>1)
		{
			$.messager.alert('提示', "只能选择一项修改");
		}else if(rows.length==0)
		{
			$.messager.alert('提示', "请选择要修改的文档");
		}else{
			var oid=rows[0].id;
			var defaultTabId = "cmTabs";
			if(tabId){
				defaultTabId = tabId;
			}
			var tabDefault = {
				href:pageBaseUrl+"shmged/jsp/com/shlcm/documents/updateDoc.jsp?oid="+oid+"&type=search",
				title:"修改文档",
				selected: true,
				closable:true
			};
			var options ;
			if(tabObj){
			    var empty = {};
				options = $.extend(empty,tabDefault,tabObj);
			}else{
				options = tabDefault;
			}
			if($('#'+defaultTabId).tabs("exists",options.title)){
				$('#'+defaultTabId).tabs('select',options.title);
			}else{
			    $('#'+defaultTabId).tabs('add',options);
			}
	//		alert(tab.outerHeight()+":"+tab.innerHeight());
	//	    alert("index:"+index);
			//var oldHeight = p.panel('panel').outerHeight();  
			//setHeight();
		}
	}
	
</script>
</div>